'''
Created on 2009-10-30

@author: yuchen
'''
import uuid
import ai.abstract_player
import copy

class CheckerPlayer(object):
	'''
	classdocs
	'''
	def __init__(self, name):
		'''
		Constructor
		'''
		self.pieces = []
		self.piece_count = 0
		self.king_count = 0
		
		self.name = name
		self.game_id = uuid.uuid4()
		
		self.ai = None
	
	def __eq__(a , b):
		if b == None:
			return False
		return a.game_id == b.game_id
	
	def __str__(self):
		return '{0} - [{1}]'.format(self.name, self.game_id)
	
	def getName(self):
		return self.name
	
	def add_piece(self, piece):
		#add piece
		self.pieces.append(piece)
		self.piece_count += 1
	
	def delete_piece(self, piece):
		#delete piece from array
		if piece.king == False:
			self.piece_count -= 1
		else:
			self.king_count -= 1
		
		self.pieces.remove(piece)
	
	def turn_king(self, piece):
		self.piece_count -= 1
		self.king_count += 1
	
	def reset(self):
		self.pieces = []
		self.piece_count = 0
		self.king_count = 0
		
	def attachAI(self, AI):
		if issubclass(AI, ai.abstract_player.AIPlayer):
			player = self
			self.ai = AI(player)
			return
		raise RuntimeError
	
	def getAI(self):
		return self.ai
	
	def getNextMove(self, state):
		return self.ai.get_move(state)

